//
//  CellForClickZhuanTiCell2.m
//  SeeTheWorld
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellForClickZhuanTiCell2.h"
#import "ModelForClickZTOfArticle.h"
#import "PCH.pch"
#import <UIImageView+WebCache.h>


@interface CellForClickZhuanTiCell2 ()

@property (nonatomic, retain)UIImageView *imageView1;
@property (nonatomic, retain)UILabel *label;

@property (nonatomic, retain)NSString *photo;
@property (nonatomic, retain)NSDictionary *note;
@property (nonatomic, retain)NSString *image_height;
@property (nonatomic, retain)NSString *image_width;

@end

@implementation CellForClickZhuanTiCell2

- (void)dealloc {
    [_imageView1 release];
    [_label release];
    [_photo release];
    [_note release];
    [_image_height release];
    [_image_width release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageView1 = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView1];
        [_imageView1 release];
        self.imageView1.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dian:)];
        [self.imageView1 addGestureRecognizer:tap];
        [tap release];
        
        self.label = [[UILabel alloc] init];
        [self.contentView addSubview:self.label];
        [_label release];
        self.label.numberOfLines = 0;
        self.label.dk_textColorPicker = DKColorWithRGB(0x343434, 0xffffff);
        self.label.font = [UIFont systemFontOfSize:14];

    }
    return self;
}

/** 点击照片手势实现 */
- (void)dian:(UITapGestureRecognizer *)tap {
    
    if (self.note == nil) {
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"passPhoto" object:nil userInfo:@{@"photo" : self.photo, @"image_width" : self.image_width, @"image_height" : self.image_height}];
        
    } else {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"passPhoto" object:nil userInfo:@{@"photo" : self.photo, @"image_width" : self.image_width, @"image_height" : self.image_height, @"note" : self.note}];

    }
    
}

/** 布局子视图 */
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.imageView1.frame = CGRectMake(10, 10, WIDTH - 20, 200);
    self.label.frame = CGRectMake(10, 221, WIDTH - 20, [[self class] heightForLabel:self.label.text]);
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(3, 3, WIDTH / 3, 30)];
    [self.imageView1 addSubview:label];
    [label release];
    label.text = @"点击查看大图";
    label.font = [UIFont systemFontOfSize:15];
    
}

/** 赋值 */
- (void)passModel:(ModelForClickZTOfArticle *)model {
   
    self.image_width = model.image_width;
    self.image_height = model.image_height;
    self.photo = model.image_url;
    self.note = model.note;
    [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"1f178a82b9014a90e9109296ad773912b31beeeb"]];
    self.label.text = model.descrip;
}

/** 自适应高度 */
+ (CGFloat)heightForLabel:(NSString *)text {
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(WIDTH - 20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil];
    
    return rect.size.height;
}

/** 自适应高度 */
+ (CGFloat)heightForCell:(ModelForClickZTOfArticle *)model {
    
    CGFloat height = [CellForClickZhuanTiCell2 heightForLabel:model.descrip];
    return height + 10 + 200 + 10 + 1;
    
}













- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
